package com.project.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.bean.EventBean;
import com.project.dao.EventDao;
import com.project.service.EventService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

/**
 * 事件
 */
@Service
@Transactional
public class EventServiceImpl extends ServiceImpl<EventDao, EventBean> implements EventService {
    @Override
    public IPage<EventBean> findAllEvent(int pageNO, int pageSize) {
        Page<EventBean> page = new Page<>(pageNO, pageSize);
        IPage<EventBean> iPage = this.page(page);
        this.baseMapper.findAllEvent();
        return iPage;
    }

    @Override
    public void addEvent(EventBean eventBean) {
        this.baseMapper.addEvent(eventBean);
    }

    @Override
    public EventBean findId(int eventId) {
        return this.baseMapper.findId(eventId);
    }

    @Override
    public void updateConsult(int eventId) {
        EventBean eventBean = new EventBean();
        eventBean.setEventId(eventId);
        eventBean.setEventStage("无法解决，申请专家会商");
        this.updateById(eventBean);
    }

    @Override
    public List<EventBean> findName(String eventName, String eventStage, String eventFind, LocalDate startTime, LocalDate endTime) {
        return this.baseMapper.findName(eventName, eventStage, eventFind, startTime, endTime);
    }

    @Override
    public void updateEvent(int eventId, String eventStage, String eventPrecept) {
        if (eventStage != null && eventPrecept != null) {
            EventBean eventBean = new EventBean();
            eventBean.setEventId(eventId);
            eventBean.setEventStage(eventStage);
            eventBean.setEventPrecept(eventPrecept);
            this.updateById(eventBean);
        } else {
            EventBean eventBean = new EventBean();
            eventBean.setEventId(eventId);
            eventBean.setEventStage("无法解决，申请专家会商");
            this.updateById(eventBean);
        }
    }
}
